from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

op = webdriver.ChromeOptions()
op.add_experimental_option('excludeSwitches', ['enable-automation'])
op.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=op)

driver.get(r"http://news.baidu.com/")


newsele = driver.find_element(By.CSS_SELECTOR,".hdline1>strong>a:nth-child(1)>b")
content = newsele.text
url = newsele.get_attribute("href")
newsele.click()
sleep(2)

current = driver.current_window_handle
all_handles = driver.window_handles
print("current,",current)
print("--------------------")
print(all_handles)

driver.switch_to.window(all_handles[1])
title = driver.title
print(title)
print("current,",driver.current_window_handle)
nowurl = driver.current_url

driver.close()
sleep(2)
driver.switch_to.window(all_handles[0])
driver.find_element(By.CSS_SELECTOR,"#ww").send_keys("喜迎二十大")
sleep(2)
driver.find_element(By.CSS_SELECTOR,"#s_btn_wr").click()
sleep(3)
print(driver.title)
assert "喜迎二十大" in driver.title
driver.quit()
